package pro.softzhang.algo.lc300;

import pro.softzhang.algo.flag.knowledge.KBinarySearch;
import pro.softzhang.algo.flag.x.XOptimal;

/**
 *
 * 374. 猜数字大小 https://leetcode.cn/problems/guess-number-higher-or-lower/description/
 */
public class LC374_GuessNumberHigherOrLower {
    public static void main(String[] args) {

    }

    static class GuessGame {
        int guess(int num) {
            return -1;
        }
    }

    /**
     * 二分查找
     */
    @KBinarySearch
    @XOptimal
    static
    class Solution extends GuessGame {
        public int guessNumber(int n) {
            int left = 1, right = n;
            while (left < right) {
                int middle = left + (right - left) / 2;
                if(guess(middle) <= 0) {
                    right = middle;
                } else {
                    left = middle + 1;
                }
            }
            return left;
        }
    }
}
